{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 第三十一题 判断回文数",
   "id": "92dbf52895c80652"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "#### 输入一个数，判断它是不是回文数。12321是回文数，个位与万位相同，十位与千位相同\n",
    "    回文数：指一个数字，从左到右读和从右到左读是完全相同的，回文数正读反读都一样"
   ],
   "id": "ae02f58b76b18d12"
  },
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-03-04T01:37:31.582383Z",
     "start_time": "2025-03-04T01:37:28.131799Z"
    }
   },
   "source": [
    "num=(input(\"请输入一个五位数\"))  #str\n",
    "def pd(n):\n",
    "    if len(n)!=5:\n",
    "        return (\"请重新输入\")\n",
    "    else:\n",
    "        c=int(n)\n",
    "        ge=c%10   #个位\n",
    "        shi=(c%100)//10  #十位\n",
    "        bai=(c%1000)//100   #百位\n",
    "        qian=(c%10000)//1000   #千位\n",
    "        wan=c//10000\n",
    "        if ge==wan and shi==qian:\n",
    "            return ('是回文数')\n",
    "        else:\n",
    "            return ('不是回文数')\n",
    "pd(num)"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'是回文数'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-04T01:45:34.141511Z",
     "start_time": "2025-03-04T01:45:28.574507Z"
    }
   },
   "cell_type": "code",
   "source": [
    "num=input(\"请输入一个数\")\n",
    "def pd(n):\n",
    "    if not n.isdigit():\n",
    "        return \"请重新输入：\"\n",
    "    else:\n",
    "        if n==n[::-1]:\n",
    "            return '是回文数'\n",
    "        else:\n",
    "            return '不是回文数'\n",
    "pd(num)"
   ],
   "id": "e7c9ab304a959df8",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'是回文数'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-04T05:15:09.429715Z",
     "start_time": "2025-03-04T05:15:06.481082Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a=input('请输入数字：')\n",
    "b=a[::-1]\n",
    "if a==b:\n",
    "    print('是回文')\n",
    "else:\n",
    "    print('不是回文')"
   ],
   "id": "794511af9bcdc5b8",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "不是回文\n"
     ]
    }
   ],
   "execution_count": 23
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 第三十二题 判断星期几",
   "id": "bb45c1414231f03c"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### 请输入星期几的第一个字母来判断一下是星期几，如果第一个字母一样，则继续判断第二个字母   ",
   "id": "580356e9c260a850"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "###### 星期一 Monday 、星期二 Tuesday 、星期三 Wednesday 、星期四 Thursday 、星期五 Friday 、星期六 Saturday 、星期日 Sunday",
   "id": "2ec12031a33a41a"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-04T02:10:45.519871Z",
     "start_time": "2025-03-04T02:10:38.166327Z"
    }
   },
   "cell_type": "code",
   "source": [
    "w=input('请输入星期几的第一个字母')\n",
    "def pd(n):\n",
    "    if n=='M' or n=='m':\n",
    "        return '星期一'\n",
    "    elif n=='T' or n=='t':\n",
    "        return '星期二'\n",
    "    elif n=='W' or n=='w':\n",
    "        return  '星期三'\n",
    "    elif n=='T' or n=='t':\n",
    "        return '星期四'\n",
    "    elif n=='F' or n=='f':\n",
    "        return '星期五'\n",
    "    elif n=='S' or n=='s':\n",
    "        w_2=input('请输入第二个字母')\n",
    "        if w_2=='a' or w_2=='A':\n",
    "            return '星期六'\n",
    "        elif w_2=='u' or w_2=='U':\n",
    "            return '星期日'\n",
    "        else:\n",
    "            pass\n",
    "    else:\n",
    "        return '请重新输入：'\n",
    "    \n",
    "pd(w)\n",
    "        "
   ],
   "id": "275a843b907e68e1",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'星期六'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 12
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-04T05:19:10.728968Z",
     "start_time": "2025-03-04T05:19:03.303579Z"
    }
   },
   "cell_type": "code",
   "source": [
    "w=input('请输入星期几的第一个字母')\n",
    "def pd(n):\n",
    "    if n=='M' or n=='m':\n",
    "        return '星期一'\n",
    "    elif n=='T' or n=='t':\n",
    "        w_2=input('请输入第二个字母')\n",
    "        if w_2=='u' or w_2=='U':\n",
    "            return '星期二'\n",
    "        elif w_2=='H' or w_2=='h':\n",
    "            return '星期四'\n",
    "        else:\n",
    "            return '请重新输入'\n",
    "    elif n=='W' or n=='w':\n",
    "        return  '星期三'\n",
    "    elif n=='F' or n=='f':\n",
    "        return '星期五'\n",
    "    elif n=='S' or n=='s':\n",
    "        w_3=input('请输入第二个字母')\n",
    "        if w_3=='a' or w_3=='A':\n",
    "            return '星期六'\n",
    "        elif w_3=='u' or w_3=='U':\n",
    "            return '星期日'\n",
    "        else:\n",
    "            return '请重新输入'\n",
    "    else:\n",
    "        return '请重新输入：'\n",
    "    \n",
    "pd(w)\n",
    "        "
   ],
   "id": "7f46a02eecb05aed",
   "outputs": [],
   "execution_count": 24
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-04T05:25:30.052010Z",
     "start_time": "2025-03-04T05:25:20.005978Z"
    }
   },
   "cell_type": "code",
   "source": [
    "w=input('请输入星期几的第一个字母')\n",
    "if w=='M' or w=='m':     \n",
    "    print('星期一')\n",
    "elif w=='T' or w=='t':\n",
    "    w_2=input('请输入第二个字母')\n",
    "    if w_2=='u' or w_2=='U':\n",
    "        print( '星期二')\n",
    "    elif w_2=='H' or w_2=='h':\n",
    "        print('星期四')\n",
    "    else:\n",
    "        print( '请重新输入')\n",
    "elif w=='W' or w=='w':\n",
    "    print('星期三')\n",
    "elif w=='F' or w=='f':\n",
    "    print('星期五')\n",
    "elif w=='S' or w=='s':\n",
    "    w_3=input('请输入第二个字母')\n",
    "    if w_3=='a' or w_3=='A':\n",
    "        print('星期六')\n",
    "    elif w_3=='u' or w_3=='U':\n",
    "        print( '星期日')\n",
    "    else:\n",
    "        print( '请重新输入')\n",
    "else:\n",
    "    print('请重新输入：')\n",
    "\n",
    "        "
   ],
   "id": "ee9d4c06a1fc7586",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "星期二\n"
     ]
    }
   ],
   "execution_count": 26
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 第三十三题 相反顺序输出列表",
   "id": "d60589424bc31799"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### 按相反的顺序输出列表的值",
   "id": "e79ecc534f6785eb"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-04T02:11:24.416015Z",
     "start_time": "2025-03-04T02:11:24.398477Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#方法一：\n",
    "list1=[1,2,3,4]\n",
    "list2=list1[::-1]\n",
    "print(list2)\n",
    "\n",
    "#方法二：\n",
    "list1.reverse()\n",
    "print(list1)"
   ],
   "id": "b59d329d74f1ebad",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[4, 3, 2, 1]\n"
     ]
    }
   ],
   "execution_count": 13
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 第三十四题 对10个数进行排序",
   "id": "1ece7ace1c7d49ae"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-04T05:27:09.214442Z",
     "start_time": "2025-03-04T05:27:09.199712Z"
    }
   },
   "cell_type": "code",
   "source": [
    "list1=[1,3,6,4,9,2,9,4,3]\n",
    "list2=sorted(list1)\n",
    "print(list2)\n",
    "\n"
   ],
   "id": "1d234fd63f9187b4",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 3, 4, 4, 6, 9, 9]\n",
      "[3, 4, 9, 2, 9, 4, 6, 3, 1]\n"
     ]
    }
   ],
   "execution_count": 27
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-04T05:50:22.676871Z",
     "start_time": "2025-03-04T05:50:13.173247Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#a=input().split()   #以空格隔开的输入  ->字符串！\n",
    "a = map(int,input().split())\n",
    "a=list(a)#list类型被覆盖，变量\n",
    "\n",
    "a.sort()\n",
    "print(a)"
   ],
   "id": "e7966b9453a5108b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 5, 6, 7, 8]\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 第三十五题 求矩阵主对角线元素之和",
   "id": "7790eb4ba45a0454"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### 求一个3*3矩阵对角线元素之和",
   "id": "b8713003ed049707"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-04T05:57:22.403981Z",
     "start_time": "2025-03-04T05:57:07.099699Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#!!!\n",
    "a=[]\n",
    "sum=0\n",
    "for i in range(3):    #行\n",
    "    a.append([])\n",
    "    for j in range(3):\n",
    "        k=int(input('请输入数据'))\n",
    "        a[i].append(k)\n",
    "        if i==j:\n",
    "            sum+=a[i][j]\n",
    "print(a)\n",
    "print(sum)"
   ],
   "id": "3d53fb596e21d2be",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1, 5, 6], [8, 2, 1], [4, 5, 6]]\n",
      "9\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 第三十六题 有序列表添加数据",
   "id": "3c529fd4dd607ae9"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### 有一个已经排好序的列表。现输入一个数，要求按原来的规律将它插入数组中",
   "id": "5928c5d32d4b593"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "list9=[1,3,5,6,7]\n",
    "#原来的规律？！哦莫哦莫"
   ],
   "id": "2d5a70dbad2cbe1"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-04T06:01:01.337638Z",
     "start_time": "2025-03-04T06:00:58.486269Z"
    }
   },
   "cell_type": "code",
   "source": [
    "list6=[2,4,6,8]\n",
    "n=int(input('请输入数据：'))\n",
    "list6.append(n)\n",
    "list6.sort()\n",
    "print(list6)"
   ],
   "id": "f31dbe8d13792f20",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 4, 6, 8]\n"
     ]
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 第三十七题 变量值互换",
   "id": "a1650ef90065876b"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### 给定两个变量，交换它们的值",
   "id": "379fdc6b16dec4d5"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "",
   "id": "a7213cd62d9b86d3"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-04T06:02:00.266981Z",
     "start_time": "2025-03-04T06:01:54.316341Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a=input('请输入第一个值')\n",
    "b=input('请输入第二个值')\n",
    "a,b=b,a\n",
    "print(a,b)"
   ],
   "id": "d309bb22d1370442",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6 5\n"
     ]
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-04T06:02:54.164339Z",
     "start_time": "2025-03-04T06:02:49.598840Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#方法二：\n",
    "a=input('请输入第一个值')\n",
    "b=input('请输入第二个值')\n",
    "temp=a\n",
    "a=b\n",
    "b=temp\n",
    "print(a,b)"
   ],
   "id": "46cb026279caaf94",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6 5\n"
     ]
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "\n",
    "# 第三十八题 产生随机数"
   ],
   "id": "77e75f88b4db0164"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-04T06:06:34.048392Z",
     "start_time": "2025-03-04T06:06:34.034718Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import random\n",
    "num1=random.random()  #0-1\n",
    "num2=random.randint(1,10)\n",
    "num3=random.randrange(1,10,3)\n",
    "print(num1,num2,num3)"
   ],
   "id": "9cbd5d059a61379f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.876458686323021 9 4\n"
     ]
    }
   ],
   "execution_count": 10
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 第三十九题 lambda表达式",
   "id": "727fd07e13868e94"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### 使用lambda来创建匿名函数",
   "id": "49492015029b514c"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-04T06:07:44.293020Z",
     "start_time": "2025-03-04T06:07:44.270641Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a=lambda x,y:x*y\n",
    "print(a(3,4))\n",
    "    "
   ],
   "id": "6edc29b550905c8c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12\n"
     ]
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 第四十题 温度转换",
   "id": "38906adc7fc64c15"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "#### 输入摄氏度，将其转为华氏度。  输入华氏温度，将其转为摄氏度\n",
    "    华氏温度与摄氏温度转换公式为： 华氏温度=摄氏温度*1.8+32"
   ],
   "id": "9f7cd5d2438e258"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-04T05:06:14.403958Z",
     "start_time": "2025-03-04T05:06:06.498185Z"
    }
   },
   "cell_type": "code",
   "source": [
    "s1=float(input('请输入摄氏度'))\n",
    "s2=s1*1.8+32\n",
    "print(f'华氏度为{s2}')\n",
    "s3=float(input('请输入华氏温度'))\n",
    "s4=(s3-32)/1.8\n",
    "print(f'摄氏温度为{s4}')\n"
   ],
   "id": "efb23058b01e823b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "华氏度为77.0\n",
      "华氏温度为0.5555555555555556\n"
     ]
    }
   ],
   "execution_count": 21
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-04T06:12:25.389917Z",
     "start_time": "2025-03-04T06:12:19.634282Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a=int(input('摄氏度按1，华氏度按2'))\n",
    "if a==1:\n",
    "    b=float(input('请输入摄氏度'))\n",
    "    result=b*1.8+32\n",
    "    print(f'华氏度为{result}')\n",
    "if a==2:\n",
    "    b=float(input('请输入华氏温度'))\n",
    "    result=(b-32)/1.8\n",
    "    print(f'摄氏温度为{result}')\n"
   ],
   "id": "278410475450c9",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "摄氏温度为37.77777777777778\n"
     ]
    }
   ],
   "execution_count": 16
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "",
   "id": "54e3fe0583d84c3b"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
